<template>
  <a-table
    rowKey="id"
    size="middle"
    bordered
    :loading="loading"
    :columns="columns"
    :dataSource="dataSource"
    :pagination="false"
  >

    <template slot="htmlSlot" slot-scope="text">
      <div v-html="text"></div>
    </template>

    <template slot="imgSlot" slot-scope="text">
      <div style="font-size: 12px;font-style: italic;">
        <span v-if="!text">无图片</span>
        <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
      </div>
    </template>

    <template slot="fileSlot" slot-scope="text">
      <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
      <a-button
              v-else
              ghost
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)"
      >
        <span>下载</span>
      </a-button>
    </template>

  </a-table>
</template>

<script>
  import { getAction } from '@api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'

  export default {
    name: 'StyleWorkingProcedureSubTable',
    mixins: [JeecgListMixin],
    props: {
      record: {
        type: Object,
        default: null,
      }
    },
    data() {
      return {
        description: '工序资料内嵌列表',
        disableMixinCreated: true,
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '序号',
            align: 'center',
            dataIndex: 'orderIndex',
          },
          {
            title: '工序',
            align: 'center',
            dataIndex: 'workingProcedure',
          },
          {
            title: '执行部门',
            align: 'center',
            dataIndex: 'dept_dictText'
          },
          {
            title: '难度级别',
            align: 'center',
            dataIndex: 'difficultLevel',
          },
          {
            title: '对内工价',
            align: 'center',
            dataIndex: 'labourCostInward',
          },
          {
            title: '对外工价',
            align: 'center',
            dataIndex: 'labourCostOutward',
          },
          {
            title: '耗率',
            align: 'center',
            dataIndex: 'attritionRate',
          },
          {
            title: '工时',
            align: 'center',
            dataIndex: 'manHour',
          },
          {
            title: '要求',
            align: 'center',
            dataIndex: 'requirement',
          },
          {
            title: '外发工价',
            align: 'center',
            dataIndex: 'labourCostOutwork',
          },
          {
            title: '单件工费',
            align: 'center',
            dataIndex: 'labourUnitCost',
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
          },
        ],
        url: {
          listByMainId: '/styleInfo/styleInfo/queryStyleWorkingProcedureByMainId',
        },
      }
    },
    watch: {
      record: {
        immediate: true,
        handler() {
          if (this.record != null) {
            this.loadData(this.record)
          }
        }
      }
    },
    methods: {

      loadData(record) {
        this.loading = true
        this.dataSource = []
        getAction(this.url.listByMainId, {
          id: record.id
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
          }
        }).finally(() => {
          this.loading = false
        })
      },

    },
  }
</script>

<style scoped>

</style>
